﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Web.Mvc;
using Business;
using Common;
using Dto;

namespace YaoYunDong.Controllers
{
    public class GroupPhotoController : ChannelBaseController
    {
        private readonly string PhotoNarrowPath = ConfigurationManager.AppSettings["PhotoNarrowPath"];
        private readonly string PhotoOriginalPath = ConfigurationManager.AppSettings["PhotoOriginalPath"];
        private readonly GroupPhotoBusiness _groupPhotoBusiness = new GroupPhotoBusiness();

        public ActionResult UpdateGroupPhoto(string[] imgNames, string code)
        {
            var groupPhotoDtos = new List<GroupPhotoDto>();
            var annexUploadUtil = new AnnexUploadUtil();
            foreach (string imgName in imgNames)
            {
                var annexDto = new AnnexDto();
                if (!string.IsNullOrEmpty(imgName))
                {
                    annexDto = annexUploadUtil.ImageUpload("/TempImage/" + imgName, imgName, 160, 160,
                                                           PhotoNarrowPath, PhotoOriginalPath, true);
                }
                var dto = new GroupPhotoDto
                              {
                                  GpAlbumId = 0,
                                  GpAnnexId = 0,
                                  GpGroupCode = code,
                                  GpName = imgName,
                                  GpSummary = "",
                                  GpTime = DateTime.Now,
                                  GpUserId = UserInfo.UserId,
                                  annex = annexDto
                              };
                groupPhotoDtos.Add(dto);
            }
            _groupPhotoBusiness.SaveGroupPhoto(groupPhotoDtos);
            return View();
        }
    }
}